package com.foreknow.springboot.threaddemo;

public class Thread2 implements Runnable{

    @Override
    public void run() {
        synchronized (WaitAndSleep.class){
            System.out.println("enter Thread2......");
            System.out.println("Thread2 is sleep......");
            //如果某个线程进入到了wait状态，需要调用该方法来唤醒等待的线程
            //只有针对此对象调用notify()方法之后进入到运行状态
            WaitAndSleep.class.notify();
            try {
                //Thread.sleep(500);这个方法导致了暂停执行指定的时间，让出cpu的资源给其他线程
                //这个时候它的监控的状态依然保持着，当指定的时间到了就会恢复运行的状态
                //在调用sleep方法的过程中，线程不会释放对象锁
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("Thread2 is going on......");
            System.out.println("Thread2 is over......");
        }
       }
}
